package com.example.mall.web.controller;

import com.example.mall.domain.PaymentSecurityLogs;
import com.example.mall.dto.PaymentSecurityLogsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.PaymentSecurityLogsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IPaymentSecurityLogsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/paymentSecurityLogs")
public class PaymentSecurityLogsController {

    @Autowired
    public IPaymentSecurityLogsService paymentSecurityLogsService;

    /**
     * 分页查询支付安全记录表信息
     * @param paymentSecurityLogsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询支付安全记录表信息",notes = "分页查询支付安全记录表信息",httpMethod = "GET")
    public JSONResult queryPage(PaymentSecurityLogsQuery paymentSecurityLogsQuery){
        PageDTO<PaymentSecurityLogsDto> paymentSecurityLogsDtoPageDTO = paymentSecurityLogsService.queryPage(paymentSecurityLogsQuery);
        return JSONResult.success("查询成功",paymentSecurityLogsDtoPageDTO);
    }

    /**
     * 根据id查询支付安全记录表信息
     * @param logId
     * @return
     */
    @GetMapping("query/{logId}")
    @ApiOperation(value = "根据id查询支付安全记录表信息",notes = "根据id查询支付安全记录表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("logId")Long logId){
        //1.根据id查询用户信息
        if (logId == null){
            throw new GlobalCustomerException(ErrorEnumCode.PAYMENT_SECURITY_LOGS_NOT_ID);
        }
        PaymentSecurityLogs paymentSecurityLogs = paymentSecurityLogsService.getById(logId);
        return JSONResult.success("查询成功",paymentSecurityLogs);
    }

    /**
     * 根据id查询支付安全记录表信息
     * @param logId
     * @return
     */
    @GetMapping("queryPaymentSecurityLogsById/{logId}")
    @ApiOperation(value = "根据id查询支付安全记录表信息",notes = "根据id查询支付安全记录表信息",httpMethod = "GET")
    public JSONResult queryPaymentSecurityLogsById(@PathVariable("logId")Long logId){
        //1.根据id查询用户信息
        if (logId == null){
            throw new GlobalCustomerException(ErrorEnumCode.PAYMENT_SECURITY_LOGS_NOT_ID);
        }
        PaymentSecurityLogs paymentSecurityLogs = paymentSecurityLogsService.queryPaymentSecurityLogsById(logId);
        return JSONResult.success("查询成功",paymentSecurityLogs);
    }

    /**
     * 查询全部支付安全记录表信息
     * @param
     * @return
     */
    @GetMapping("queryPaymentSecurityLogsist")
    @ApiOperation(value = "查询全部支付安全记录表信息",notes = "查询全部支付安全记录表信息",httpMethod = "GET")
    public JSONResult queryPaymentSecurityLogsist(){
        List<PaymentSecurityLogs> paymentSecurityLogs = paymentSecurityLogsService.queryPaymentSecurityLogsist();
        return JSONResult.success("查询成功",paymentSecurityLogs);
    }

    /**
     * 新增支付安全记录表
     * @param paymentSecurityLogsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增支付安全记录表",notes = "新增支付安全记录表",httpMethod = "POST")
    public JSONResult insert(@RequestBody PaymentSecurityLogsDto paymentSecurityLogsDto){
        paymentSecurityLogsService.insert(paymentSecurityLogsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改支付安全记录表信息
     * @param paymentSecurityLogsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改支付安全记录表信息",notes = "修改支付安全记录表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody PaymentSecurityLogsDto paymentSecurityLogsDto){
        paymentSecurityLogsService.update(paymentSecurityLogsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除支付安全记录表信息
     * @param logId
     * @return
     */
    @PostMapping("delete/{logId}")
    @ApiOperation(value = "删除支付安全记录表信息",notes = "删除支付安全记录表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("logId") Long logId) {
        paymentSecurityLogsService.delete(logId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除支付安全记录表信息
     * @param logIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除支付安全记录表信息",notes = "批量删除支付安全记录表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> logIds) {
        paymentSecurityLogsService.deleteBatch(logIds);
        return JSONResult.success("批量删除成功");
    }
}
